/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.BusinessLogicLayer;

import edu.nii.qlks.DataAccessLayer.MSSQLConnectUnit;
import edu.nii.qlks.DataTransferObject.ThucDonInfo;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author MARS_NHO
 */
public class ThucDonBLL {
    MSSQLConnectUnit _connect;
    ResultSet  _result;
 
    public ArrayList LayDS(String Condition, String OderBy) throws Exception{
        ArrayList vt = new ArrayList();
        
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.Select("THUCDON", Condition, OderBy);
        
        while (_result.next()){
            ArrayList vt_row = new ArrayList();
            vt_row.add(_result.getString(1));
            vt_row.add(_result.getString(2));
            vt_row.add(_result.getString(3));
            vt.add(vt_row);
        }
        _connect.Close();
        return vt;
    }
    
    public ArrayList LayDS(String Condition) throws Exception{
         return LayDS(Condition, null);
    }
    
    public ArrayList LayDS() throws Exception{
        return LayDS(null);
    }
    
    public void Insert(ThucDonInfo thucDonInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<>();
        map.put("MaThucDon", thucDonInfo.getMaThucDon());
        map.put("TenThucDon", thucDonInfo.getTenThucDon());
        map.put("DonGia", thucDonInfo.getDonGia());
        _connect.Insert("THUCDON", map);
    }
    
     
    public void Inserts(HashSet<ThucDonInfo> thucDonInfos) throws Exception{
        for (ThucDonInfo thucDonInfo:thucDonInfos) {
            this.Insert(thucDonInfo);
        }
    }
    
    public void Update(ThucDonInfo thucDonInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<>();
        map.put("TenThucDon", thucDonInfo.getTenThucDon());
        map.put("DonGia", thucDonInfo.getDonGia());
        _connect.Update("THUCDON", map, "MaThucDon = '" + thucDonInfo.getMaThucDon() + "'");
    }
    
    public void Updates(HashSet<ThucDonInfo> thucDonInfos) throws Exception{
        for (ThucDonInfo thucDonInfo:thucDonInfos){
            this.Update(thucDonInfo);
        }
    }
    
    public void Delete(ThucDonInfo thucDonInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _connect.Delete("THUCDON", "MaThucDon = " + thucDonInfo.getMaThucDon());
    }
    
    public void Deletes(HashSet<ThucDonInfo> thucDonInfos) throws Exception{
         for (ThucDonInfo thucDonInfo:thucDonInfos){
            this.Delete(thucDonInfo);
        }
    }
    
    public String TaoMaTuDong(String maGoc, int batDau){
        String ma = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.TaoMaTuDong(maGoc, batDau);
        return ma;
    }
}
